package main.view;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import main.util.DBTool;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;


public class Main extends Application {
    private static Stage stage;
    private static Connection connection;
    public Connection getConnection(){
        return connection;
    }
    @Override
    public void start(Stage stage) throws Exception {
        Main.stage = stage;
        initLogin();
    }
    @Override
    public void init() throws SQLException {
        connection = DBTool.getConnetion();
    }
    public void initLogin() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/login.fxml"));

        Parent root = fxmlLoader.load();
        Scene login = new Scene(root);
        Main.stage.setScene(login);
        Main.stage.setResizable(false);
        Main.stage.setTitle("广师大图书管理系统");
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));
        Main.stage.show();
    }
    public void initRegister() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/userRegister.fxml"));
        Parent root = fxmlLoader.load();
        Scene register = new Scene(root);

        Main.stage.setScene(register);
        Main.stage.setTitle("注册页面");
        Main.stage.getIcons().add(new Image("https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/434/202207080016504.png"));
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));

        Main.stage.show();
    }
    public void initRootLogin() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/rootLogin.fxml"));
        Parent  root = fxmlLoader.load();
        Scene register = new Scene(root);

        Main.stage.setScene(register);
        Main.stage.setTitle("管理员登录");

        Main.stage.getIcons().add(new Image("https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/434/202207080016504.png"));
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));

        Main.stage.show();
    }
    public void initUserMenu() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/userMenu.fxml"));
        Parent  root = fxmlLoader.load();
        Scene usermenu = new Scene(root);

        Main.stage.setScene(usermenu);
        Main.stage.setTitle("借阅界面");
        Main.stage.getIcons().add(new Image("https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/434/202207080016504.png"));
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));

        Main.stage.show();

    }
    public void initAdminMenu() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/adminMenu.fxml"));
        Parent  root = fxmlLoader.load();
        Scene adminmenu = new Scene(root);

        Main.stage.setScene(adminmenu);
        Main.stage.setTitle("管理员模式");
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));
        Main.stage.show();

    }
    public void initBackBook() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/returnBook.fxml"));
        Parent  root = fxmlLoader.load();
        Scene backBook = new Scene(root);
        Main.stage.setScene(backBook);
        Main.stage.setTitle("还书窗口");
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));
        Main.stage.show();
    }
    public void initBorrowBook() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/borrowBook.fxml"));
        Parent  root = fxmlLoader.load();
        Scene borrowBook = new Scene(root);
        Main.stage.setScene(borrowBook);
        Main.stage.setTitle("借书窗口");
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));
        Main.stage.show();
    }
    public void initBookInLibrary() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/bookStorage.fxml"));
        Parent  root = fxmlLoader.load();
        Scene booksInLibrary = new Scene(root);
        Main.stage.setScene(booksInLibrary);
        Main.stage.setTitle("图书入库窗口");
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));
        Main.stage.show();
    }
    public void changeUserInformation() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/changeUserInformation.fxml"));
        Parent  root = fxmlLoader.load();
        Scene changeUserInformation = new Scene(root);
        Main.stage.setScene(changeUserInformation);
        Main.stage.setTitle("用户信息修改窗口");
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));
        Main.stage.show();
    }
    public void bindStatus() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/bindStatus.fxml"));
        Parent  root = fxmlLoader.load();
        Scene disabledState = new Scene(root);
        Main.stage.setScene(disabledState);
        Main.stage.setTitle("账号状态");
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));
        Main.stage.show();
    }
    public void mangeBook() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/mangeBook.fxml"));
        Parent  root = fxmlLoader.load();
        Scene mangeBook = new Scene(root);
        Main.stage.setScene(mangeBook);
        Main.stage.setTitle("管理图书");
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));
        Main.stage.show();
    }
    public void typeBook() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("../../resources/typeBook.fxml"));
        Parent  root = fxmlLoader.load();
        Scene mangeBook = new Scene(root);
        Main.stage.setScene(mangeBook);
        Main.stage.setTitle("管理图书");
        Main.stage.getIcons().add(new Image("resources/image/logo.png"));
        Main.stage.show();
    }
    public void exit() throws IOException {
//        DBTool.close(connection);
//        Main.stage.close();
        initLogin();
    }
    public static void main(String[] args) {
        launch(args);
    }

}
